<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <div id="app">
      <ul>
        <li><router-link to="/">Home</router-link></li>
      </ul>
      <router-view></router-view>
    </div>
    <script src="vue.js"></script>
    <script src="vue-router.js"></script>
    <script>
      const Home = {
        template: `<div>Home</div>`,
        created(){
          throw new Error('在Home组件中发生了错误')
        }
      };

      const routes = [
        { 
          name: "home", 
          path: "/", 
          component: Home 
        }
      ];

      var router = new VueRouter({
        routes,
      });
      Vue.config.errorHandler = function(err,vm,info){
        console.log(err);//抛出的错误对象
        console.log(vm);//Home组件实例
        console.log(info);//created hook
      }
      var vm = new Vue({
        el: "#app",
        router,
      });
    </script>
  </body>
</html>
